package com.fivetalks.controller.web;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fivetalks.dao.GuestbookDAO;
import com.fivetalks.domain.Guestbook;


@Controller
public class GuestbookController {
	@Autowired
	private GuestbookDAO guestbookDAO;
	
	// http://127.0.0.1/boardorm/g_list
	@RequestMapping(value="/g_list", method = RequestMethod.GET)
	public String g_list(Model model){
		
		List<Guestbook> list = guestbookDAO.getAll();
		
		model.addAttribute("list", list);
		
		return "g_list";
	}
	
	@RequestMapping(value="/g_writeform", method = RequestMethod.GET)
	public String g_writeform(){
		
		return "g_writeform";
	}
	
	@RequestMapping(value="/g_write", method = RequestMethod.POST)
	public String g_write(@ModelAttribute Guestbook guest){
		
		guestbookDAO.save(guest);
		return "redirect:/g_list";
	}	
}
